package
{
	
	import com.crl.core.ClassFactory;
	import com.crl.core.config.ConfigurationManager;
	import com.crl.module.connecter.core.Connecter;
	import com.crl.module.dragger.AbstractDragger;
	import com.crl.module.dragger.DragManager;
	import com.crl.module.eventParser.EventParserFactory;
	import com.crl.module.pool.ObjectPool;
	import com.crl.module.pool.ObjectPoolCache;
	import com.crl.ui.bitmaps.AnimatedBitmap;
	import com.crl.ui.bitmaps.Grid9BitmapDecoration;
	import com.crl.ui.controls.listClass.ListItemRenderer;
	import com.crl.ui.controls.pages.PageList;
	import com.crl.ui.controls.pages.TabPageSkin;
	import com.crl.utils.color.HSLPanel;
	import com.crl.utils.color.HSMixer;
	import com.crl.utils.color.RGB;
	import com.crl.utils.color.SaturationMixer;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	//[Frame(factoryClass="com.crl.ui.preloaders.Preloader")]
	public class Main extends Sprite
	{
		private var eventFactory:EventParserFactory;
		
		private var mixer:HSMixer;
		private var saturation:SaturationMixer;
		
		private var g:Graphics;
		public function Main()
		{
			stage.align=StageAlign.TOP_LEFT;
			stage.scaleMode=StageScaleMode.NO_SCALE;
			
			var a:Point=new Point(50,50);
			var b:Point=new Point(110,100);
			
			var c:Point=new Point(60,80);
			
			
			g=this.graphics;
			g.lineStyle(1,0);
			g.moveTo(a.x,a.y);
			g.lineTo(b.x,b.y);
			
			
			
			
			
			
			
			
			
			var r:Number=dis(a,b,c);
			trace(r);
		}
		
		
		
		private function dis(a:Point,b:Point,c:Point):Number{
			var ab:Point=new Point((b.x-a.x),(b.y-a.y));
			
			var ac:Point=new Point((c.x-a.x),(c.y-a.y));
			
			var dot:Number=ab.x*ac.x+ab.y*ac.y;
			
			var t:Number=Math.pow((a.x-b.x),2)+Math.pow((a.y-b.y),2);
			dot=dot/t;
			
			var r:Point=ab.clone();
			r.x*=dot;
			r.y*=dot;
			
			r.x+=a.x;
			r.y+=a.y;
			
			
			g.lineStyle(1,0);
			g.moveTo(c.x,c.y);
			g.lineTo(r.x,r.y);
			
			return Point.distance(c,r);
		}
		
		
		private function test333():void{
			var ob:ObjectPool=new ObjectPool(new ClassFactory(RGB),10);
			
			ObjectPoolCache.getInstance();
			
			var fac:ClassFactory=new ClassFactory(ListItemRenderer)
			new PageList(fac,50,100);
		}
		
		
		private function secondTest():void{
			var p:HSLPanel=new HSLPanel();
			p.color=0x2F2A1D;
			return 
			
			new AnimatedBitmap(new BitmapData(200,300,true),10,24);
			
			trace("main")
			return;
			stage.align=StageAlign.TOP_LEFT;
			stage.scaleMode=StageScaleMode.NO_SCALE;
			
			
			var bitmap:Bitmap=new image()
			var g:com.crl.ui.bitmaps.Grid9BitmapDecoration=new Grid9BitmapDecoration(bitmap.bitmapData);
			addChild(g);
			g.x=g.y=50
			g.resize(200,100);
			return;
			
			var nav:TabPageSkin=new TabPageSkin(false);
			
			this.addChild(nav);
			
			var sp:MovieClip;
			
			
			for(var i:int=2;i<=10;i++){
				sp=getButton(0xFFFFFF<<(i*3),30+10*Math.random())
				nav.addTab(sp);
			}
			
			var next:Sprite=getButton(0x990000,20);
			next.y=50 ,next.x=100;
			
			addChild(next);
			
			var prev:Sprite=getButton(0xcc0000,10);
			prev.y=50 ,prev.x=50;
			
			addChild(prev);
			
			nav.bindButton(prev,next);
		
		}
		
		
		private  function getButton(clr:Number,size:int):MovieClip{
			var sp:MovieClip=new MovieClip;
			var g:Graphics=sp.graphics;
			
			g.clear();
			g.beginFill(clr);
			g.drawRect(0,0,size,size);
			g.endFill();
			return sp;
		}
		
		private function oldTest():void{
			new Connecter();
			
			
			ConfigurationManager.getSection("dd");
			
			
			DragManager.startDrag(new AbstractDragger,null,null);
			
			eventFactory=new EventParserFactory();
			//eventFactory.addParser(new TestEventParser());
			//eventFactory.addParser(new FuckParser(),false,10);
			
			//eventFactory.dispatchEvent(new TestEvent(TestEvent.TEST));
		}
		
		
		private function completeHandler(event:Event):void{
			
			var mc:Sprite=(event.target as LoaderInfo).content as Sprite;

			mc.addEventListener(MouseEvent.CLICK,clickHandler);
			
			this.addChild(mc);
		}
		
		private function clickHandler(event:Event):void{
			trace(event.target);
		}
		
		private function back():void{
			trace("finisehd")
		}
	}
}